﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Linq;
namespace WPFExcelReport
{
    public partial class TCGB14
    {


        public TCGB14()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_GABEW();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void OnEXAUFChg(string vlaue)
        { 
            TBMain.Clear();
            if (EXAUF.Length < 154)
                return;
            dwData = TBMain.NewRow();
            dwData["GABMANDANT"] = app.Mandant;
            dwData["GABLO"] = EXAUF.Substring(0, 2);
            dwData["GABLB"] = EXAUF.Substring(2, 2);
            dwData["GABBUCHDAT"] = EXAUF.Substring(4, 8);
            dwData["GABART"] = EXAUF.Substring(13, 20);
            dwData["GABVAR"] = EXAUF.Substring(33, 2).PadRight(3);
            dwData["GABFARBE"] = EXAUF.Substring(35, 10);
            dwData["GABBS"] = EXAUF.Substring(152, 2);
            SResult = TMV.QGABEW07(dwData);
            MergeData(SResult, false);
            base.OnEXAUFChg(vlaue); 
        }

        public void WBWAdjustCommand(object sender, RoutedEventArgs e)
        {
            string RDATE = "";
            if (dwMaster == null)
                return;
            if (!IsNew)
            {
                if (!IsEdit)
                {
                    INFO = "";
                }
                IsNew = true;
                IsEdit = true;
                dwData = TMV.STKG.TBMain.NewRow();
                RDATE = dwMaster["GABBUCHDAT"].ToString();
                if (!INFO.Contains(RDATE + ";"))
                    INFO += RDATE + ";";
                dwData["MDATE"] = dwMaster["GABBUCHDAT"];
                dwData["WAKZ"] = "G";
                dwData["LO"] = dwMaster["GABLO"];
                dwData["LB"] = dwMaster["GABLB"];
                TMV.STKG.DSTKG02(dwData);

                return;
            }


            TMV.UGBW02(dwMaster);

            TMV.VGBW.UTGBW04(dwMaster);

            dwData = TMV.STKG.TBMain.NewRow();

            dwData["MDATE"] = dwMaster["GABBUCHDAT"];
            RDATE = dwMaster["GABBUCHDAT"].ToString();
            if (!INFO.Contains(RDATE + ";"))
                INFO += RDATE + ";";

            dwData["WAKZ"] = "G";
            dwData["LO"] = dwMaster["GABLO"];
            dwData["LB"] = dwMaster["GABLB"];
            TMV.STKG.DSTKG02(dwData);
            IsNew = false;

        }

        private void DailyAdjustCommand(object sender, RoutedEventArgs e)
        {
            string[] dates = INFO.Split(';');
            foreach (string dat in dates)
            {
                TMV.STK.EXEDGI09(dat, 1, "G");
            }
            INFO = "";
            IsEdit = false;
        }
    }
}
